<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<div id="batchCreateDialog" class="container-fluid">
    <div class="row">
        <form id="batchCreateForm" class="form-horizontal" method="post" action="${basePath}/manage/umbrella/batchCreate" ENCTYPE="multipart/form-data">
            <div class="form-group">
                <label class="col-sm-4 control-label" >
                    文件：
                </label>
                <div class="col-sm-5 col-sm-offset-4">
                    <input type="file" name="file" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label" >
                </label>
                <div class="col-sm-5 col-sm-offset-4" style="color:red;">
                     单次导入最多支持500条数据。
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label" >
                    默认当前用户代理：
                </label>
                <div class="col-sm-5 col-sm-offset-4">
                    <input type="checkbox" id="defaultCurAgent_checked" name="defaultCurAgent_checked" checked>&NonBreakingSpace;
                    <input type="hidden"id="defaultCurAgent" name="defaultCurAgent" value="1">&NonBreakingSpace;
                    <a class="lobibox-notify-info" href="javascript:;" data-toggle="tooltip" title="启用则将导入雨伞默认为当前登陆用户所有；否则在机器端进伞时再自动分配。"><i class="glyphicon glyphicon-info-sign"></i></a>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label" >
                    模板下载：
                </label>
                <div class="col-sm-5">
                    <a class="link_a" href="${basePath}/resources/temp/批量新增雨伞模板.csv" download="批量新增雨伞模板.csv">批量新增雨伞模板.csv</a>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-8 col-sm-offset-4">
                    <button type="button" class="btn btn-primary"  onclick="beforeSubmit()">
                        保存
                    </button>
                    <button type="button" class="btn btn-default"
                            onclick="batchCreateDialog.close();">取消
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    var index;
    function beforeSubmit(){
        index = layer.load(0, {shade: false});
        $('#batchCreateForm').ajaxSubmit({
            success: showResponse,
            error: function () {
                infoDialog("服务器错误！");
            }
        });
    }

    /**
     * 保存后，执行回调
     * @param responseText
     * @param statusText
     * @param xhr
     * @param $form
     */
    function showResponse(obj, statusText, xhr, $form){
        layer.close(index);
        //        {"code":0,"message":"failed","data":"存在错误数据，批量导入失败。"}
        var result = JSON.parse(obj);
        if(result.code === 0){
            infoDialog(result.data);
        } else {
            infoDialog(result.data);
        }
    }

</script>